package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.MenuDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author ：w
 * @date ：Created in 2019/7/30 0030
 * @description ：菜单业务实现类
 * @version: 1.0
 */
@Service
@Slf4j
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuDao menuDao;
    @Override
    public PageResult findMenuListByPage(Integer currentPage, Integer pageSize, String queryString) {
        log.debug("<<<<<<<<<<<currentPage,pageSize,queryString:{}" + currentPage+","+pageSize+","+queryString);
            PageHelper.startPage(currentPage, pageSize);
            Page<Menu> menus = menuDao.selectByCondition(queryString);
            return new PageResult(menus.getTotal(), menus.getResult());
    }

    @Transactional
    @Override
    public void addOneRecord4Menu(Map map) {
        menuDao.add(map);
    }

    @Transactional
    @Override
    public void updateOneRecord4Menu(Map map) {
        menuDao.updateOneRecord4Menu(map);
    }

    @Override
    public Menu findMenuById(Integer id) {
        return menuDao.findMenuById(id);
    }

    @Transactional
    @Override
    public void delOneRecord4Menu(Integer id) {
        menuDao.delOneRecord4Menu(id);
    }
}
